import React from 'react';
import { Image, Text, View } from '@tarojs/components';
import ListItem from '@/components/ListItem';
import { GStyleSheet } from '@/utils/DarkMode';
import i18n from 'i18n-js';
import Taro from '@tarojs/taro';

const bleIcon =
  'https://xbgroup-1251025085.cos.ap-guangzhou.myqcloud.com/cybertron/users/495101/media/icon_bluetooth%403x_1677226818195.png';
const alarmIcon =
  'https://xbgroup-1251025085.cos.ap-guangzhou.myqcloud.com/cybertron/users/495101/media/icon_tips%403x_1677226813191.png';

const dstyles = GStyleSheet.create({
  container: {
    display: 'flex',
    backgroundColor: '#F4F4F4',
    width: '80%',
    borderRadius: 14,
    height: 50,
    marginBottom: 10,
  },
  text: {
    color: '#333333',
    fontSize: 16,
  },
  tips: {
    color: '#0079F5',
    textDecorationLine: 'underline',
  }
});

const AlertTitleItem: React.FC<{errorType: 'BLE' | 'LOCATION'}> = ({errorType = 'BLE'}) => {
  const styles = dstyles.useDynamicStyle();
  return (
    <View style={{ display: 'flex', flexDirection: 'column', width: '100%', justifyContent: 'center', alignItems: 'center' }}>
      <ListItem style={styles.container} icon={<Image src={alarmIcon} style={{ width: 30, height: 30 }} />}>
        <View style={{ display: 'flex', flexDirection: 'column', alignItems: 'flex-start' }}>
          <View style={{ display: 'flex', alignItems: 'center' }}>
            <Text style={styles.text}>{errorType === 'BLE' ? i18n.t('OPEN_BLE') : i18n.t('OPEN_LOCATION')}</Text>
          </View>
          <View style={styles.tips} onClick={() => {
              if (errorType === 'BLE') {
                Taro.navigateTo({
                  url: '/pages/BleTips/index'
                })
              } else {
                Taro.navigateTo({
                  url: '/pages/BleTips/location'
                })
              }
            }}>
              {errorType === 'BLE' ? i18n.t('蓝牙权限指引') : i18n.t('位置权限指引')}
          </View>
        </View>
      </ListItem>
    </View>

  );
};

export default AlertTitleItem;
